home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / imb9004.zip / BONUS2.BAS next >
BASIC Source File  |  1990-04-01  |  2KB  |  94 lines

  1. DECLARE FUNCTION GetSizeOfFile& (FileNumber AS INTEGER)
  2. 'Program: BONUS2.BAS
  3.  
  4. 'This program demonstrates a way to save room
  5. 'in DGROUP by storing string data outside the
  6. 'program, but within the EXE file.
  7.  
  8. TYPE DataRec1
  9.     CoName   AS STRING * 30
  10.     FName    AS STRING * 15
  11.     LName    AS STRING * 20
  12.     Phone    AS STRING * 14
  13.     CRLF     AS STRING * 2
  14. END TYPE
  15.  
  16. TYPE DataRec2
  17.     CoName  AS STRING * 30
  18.     CoAddr1 AS STRING * 30
  19.     CoAddr2 AS STRING * 30
  20.     CoCity  AS STRING * 20
  21.     CoState AS STRING * 2
  22.     CoZip   AS STRING * 9
  23. END TYPE
  24.  
  25. DIM TestRec1 AS DataRec1
  26. DIM TestRec2 AS DataRec2
  27.  
  28. CLS
  29. OPEN "B", 1, "K:\BONUS2\NEWTEST.EXE"
  30. InitLoc& = GetSizeOfFile&(1) + 1
  31.  
  32. GET #1, InitLoc&, TestRec1
  33.  
  34. PRINT TestRec1.CoName
  35. PRINT TestRec1.LName + ", " + TestRec1.FName
  36. PRINT TestRec1.Phone
  37.  
  38. 'The " + 1 " skips <EOF> character at end of record
  39. GET #1, , TestRec2
  40.  
  41. PRINT : PRINT
  42. PRINT TestRec2.CoName
  43. PRINT TestRec2.CoAddr1
  44. PRINT TestRec2.CoAddr2
  45. PRINT TestRec2.CoCity
  46. PRINT TestRec2.CoState
  47. PRINT TestRec2.CoZip
  48.  
  49. 'To write to EXE file use Put
  50. 'file number & offset as follow
  51.  
  52. '  To write TestRec1
  53.  
  54. TestRec1.LName = "Jr."
  55. PUT #1, InitLoc&, TestRec1
  56.  
  57. '  To write TestRec2
  58.  
  59. TestRec2.CoName = "THE COBB GROUP, INC."
  60. PUT #1, , TestRec2
  61.  
  62. CLOSE #1
  63. END
  64.  
  65. FUNCTION GetSizeOfFile& (FileNumber AS INTEGER)
  66.  
  67. 'This function returns the actual size of
  68. 'programs in a long variable.  Pass the routine
  69. 'the file number used to open the file
  70.  
  71. 'Read 1st 6 bytes of hdr
  72.     A$ = INPUT$(6, FileNumber)
  73.  
  74. 'Calculate the number of partial pages used in
  75. '  the program file, if any.  This number is stored
  76. '  in bytes 3 and 4.
  77.     Fraction& = ASC(MID$(A$, 4)) * 256& + ASC(MID$(A$, 3))
  78.  
  79. 'Calculate the number of whole pages used to
  80. '  store the file.           
  81.     Pages& = ASC(MID$(A$, 6)) * 256& + ASC(MID$(A$, 5))
  82.  
  83. 'If there are any fractional pages subtract 1
  84. '  from the pages count.
  85.     IF Fraction& THEN Pages& = Pages& - 1
  86.  
  87. 'Each page is 512 bytes long so multiply 512
  88. '  times the number of pages and add any
  89. '  fractional bytes to the total.
  90.     GetSizeOfFile& = Pages& * 512& + Fraction&
  91.  
  92. END FUNCTION
  93.  
  94.